<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
	<title>校友管理-校友信息管理-添加</title>
	<link rel="icon" href="favicon.ico" type="image/ico">
	<meta name="keywords" content="添加">
	<meta name="author" content="yinqi">
	<link href="/css/bootstrap.min.css" rel="stylesheet">
	<link href="/css/materialdesignicons.min.css" rel="stylesheet">
	<link href="/css/style.min.css" rel="stylesheet">

</head>
<body>

<div class="row">
	<div class="col-lg-12">
		<div class="card">
			<div class="card-body">

				<form action="/stu/SaveStu" method="post" class="row" enctype="multipart/form-data">
					<div class="form-group col-md-3">
						<label for="departId">院系</label>
						<div class="form-controls">
							<select name="departId" class="form-control" id="departId" onchange="getSpec()">
								<option value="0">选择院系</option>
							</select>
						</div>
					</div>

					<div class="form-group col-md-3">
						<label for="specId">专业</label>
						<div class="form-controls">
							<select name="specId" class="form-control" id="specId" onchange="getClass()">
								<option value="0">选择专业</option>
							</select>
						</div>
					</div>

					<div class="form-group col-md-3">
						<label for="classId">班级</label>
						<div class="form-controls">
							<select name="classId" class="form-control" id="classId">
								<option value="0">选择班级</option>
							</select>
						</div>
					</div>
					<div class="form-group col-md-12"></div>
					<div class="form-group col-md-3">
						<label for="name">姓名</label>
						<input type="text" class="form-control" id="name" name="name" value="" placeholder="请输入姓名" />
					</div>
					<div class="form-group">
						<label class="col-xs-12" for="stuImg">上传头像</label>
						<div class="col-xs-12">
							<input type="file" accept="image/jpg,image/png,image/gif" id="stuImg" name="file" onchange="fileChange(this)">
						</div>
					</div>
					<div class="form-group col-md-12"></div>
					<div class="form-group col-md-3">
						<label>性别</label>
						<div class="clearfix">
							<label class="lyear-radio radio-inline radio-primary">
								<input type="radio" name="sex" value="男" checked><span>男</span>
							</label>
							<label class="lyear-radio radio-inline radio-primary">
								<input type="radio" name="sex" value="女" ><span>女</span>
							</label>
						</div>
					</div>
					<div class="form-group col-md-12"></div>
					<div class="form-group col-md-3">
						<label>权限</label>
						<div class="clearfix">
							<label class="lyear-radio radio-inline radio-primary">
								<input type="radio" name="isAdmin" value="0" checked><span>用户</span>
							</label>
							<label class="lyear-radio radio-inline radio-primary">
								<input type="radio" name="isAdmin" value="1" ><span>管理员</span>
							</label>
						</div>
					</div>
					<div class="form-group col-md-12"></div>
					<div class="form-group col-md-3">
						<label for="mobile">手机</label>
						<input type="text" class="form-control" id="mobile" name="mobile" value="" placeholder="请输入手机号" />
					</div>

					<div class="form-group col-md-12"></div>
					<div class="form-group col-md-3">
						<label for="email">email</label>
						<input type="text" class="form-control" id="email" name="email" value="" placeholder="请输入邮箱" />
					</div>

					<div class="form-group col-md-12"></div>
					<div class="form-group col-md-3">
						<label for="job">工作信息</label>
						<input type="text" class="form-control" id="job" name="job" value="" placeholder="" />
					</div>
					<div class="form-group col-md-12"></div>
					<div class="form-group col-md-3">
						<label for="address">地址</label>
						<input type="text" class="form-control" id="address" name="address" value="" placeholder="" />
					</div>

					<div class="form-group col-md-12">
						<button type="submit" class="btn btn-primary ajax-post" target-form="add-form">确 定</button>
						<button type="button" class="btn btn-default" onclick="javascript:history.back(-1);return false;">返 回</button>
					</div>
				</form>

			</div>
		</div>
	</div>

</div>
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/js/perfect-scrollbar.min.js"></script>
<script type="text/javascript" src="/js/main.min.js"></script>
<script type="text/javascript" src="/js/axios.min.js"></script>
<script type="text/javascript">
    $(function () {
        //异步请求获取所有的院系
        axios.post('/dep/getAllDepart')
            .then(function (response) {
                var data=response.data;
                console.log(data);
                $.each(data,function (index,depart) {

                    $("#departId").append("<option value="+depart.departId+">"+depart.departName+"</option>")
                })
            })
    });
    function getSpec() {
        $("#specId").html("<option value=\"0\">选择专业</option>");
        //根据院系ID，异步请求获取对应的专业信息，
        var departId=$("#departId").val();
        axios.get('/spec/getSpecById?departId='+departId)
            .then(function (response) {
                var data=response.data;
                console.log(data);
                $.each(data,function (index,spec) {

                    $("#specId").append("<option value="+spec.specId+">"+spec.specname+"</option>")
                })
            })
    }
    function getClass() {
        $("#classId").html("<option value=\"0\">选择班级</option>");
        //根据专业ID，异步请求获取对应的班级信息，
        var specId = $("#specId").val();
		axios.get('/cla/getClaById?specId='+specId)
			.then(function (response) {
			    var data=response.data;
			    console.log(data);
			    $.each(data,function (index,cla) {
                    $("#classId").append("<option value="+cla.classId+">"+cla.className+"</option>")
				})
        })
    }

    function fileChange(target) {
        var fileSize = 0;
        fileSize = target.files[0].size;
        var size = fileSize / 1024;
        if (size > 1000) {
            alert("附件不能大于1M");
            target.value = "";
            return false;   //阻止submit提交
        }
        var name = target.value;
        var fileName = name.substring(name.lastIndexOf(".") + 1).toLowerCase();
        if (fileName != "jpg" && fileName != "png"&&fileName!="gif"&&fileName!="jpeg") {
            alert("请选择图片格式文件上传(jpg、png、gif)！");
            target.value = "";
            return false;   //阻止submit提交
        }
    }

</script>
</body>
</html>